//###############
// FILE : ComparableSizeFilter.java
// WRITER : Lior Zimmerman liorz06 066462300
// WRITER : Ohad Dan ohad_dan 036767960
// EXERCISE : oop ex3 2008
// DESCRIPTION:Filters of comparable type. 
//###############
package oop.ex3.fileSearchModel.filters;

import oop.ex3.fileSearchModel.filters.exceptions.FilterDataException;

/**
 * Filters of comparable type. 
 * @author liorz06
 * @author ohad_dan
 */
class CompareSizeFilter extends ComparableFilter<Long> {
	//********************************************************************
	//  Data members :                                                   *
	//********************************************************************
    private Long _longData;
	
	//********************************************************************
	//  Methods :                                                        *
	//********************************************************************
	/**
	 * Constructs a new compare size filter.
	 * @param compareMode The comparison mode - Bigger,Equals,Smaller.
	 */	
	public CompareSizeFilter(int compareMode ){
		super(compareMode);
    }
	/**
	 * Returns file's size. 
	 * @return File's size.
	 */
	public Long getFileData(){
		return new Long(  _file.length() );
	}
	/**
	 * Returns the size to be compared to.
	 * @return The compared size.
	 */
	public Long getComparableData(){
	    return _longData;
	}
	/**
	 *  Clones the object - return a new object with same properties.
	 *  @return A new copy of the filter.
	 */
	public Filter clone(){
	    return new CompareSizeFilter( _compareMode );
	}
	/**
	 * Sets the data of the filter.
	 * @param data The data to be set.
	 * @throws FilterDataException In case of wrong filter parameters. 
	 */
	public void setData(String data) throws FilterDataException{
	    try{
	        _longData = Long.parseLong(data);
	    }
	    catch( NumberFormatException e ){
	        throw new FilterDataException("Error:Invalid filter" +
	        		" parameters");
	    }
	}
}
